import { instance } from '../request'

const request = instance

/**
 * 获取权限列表
 *
 * @param page  分页页码
 * @param size  分页大小
 * @param sortId  分类id
 * @return
 */
export const getPermissionsListApi = (
  page: number,
  size: number,
  sortId?: string
): PromiseRes<QueryPermissionListItf> =>
  request.get(
    `/permissions/permissionsList?page=${page}&size=${size}&sortId=${
      sortId || ''
    }`
  )

/**
 * 创建权限或者修改权限信息
 *
 * @param permission   权限信息
 * @param permissionId 可选参数，修改权限时可带上，创建时无需
 * @return
 */
export const setPermissionApi = (permission: {
  name: string
  code: string
  description: string
  sortId?: string
  id?: string
}): PromiseRes => request.post(`/permissions/setPermission`, permission)

/**
 * 批量删除权限
 *
 * @param permissionIdList 权限id列表
 * @return s
 */
export const deletePermissionsApi = (permissionIdList: string[]): PromiseRes =>
  request.post(`/permissions/deletePermissions`, permissionIdList)

/**
 * 批量更新权限状态
 *
 * @param permissionIdList 权限id 列表
 * @param status           状态 0启用，1禁用
 * @return s
 */
export const updatePermissionsStatusApi = (
  permissionIdList: string[],
  status: 0 | 1
): PromiseRes =>
  request.post(
    `/permissions/updatePermissionsStatus?status=${status}`,
    permissionIdList
  )
